<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:87:"/www/web/ceshi/public_html/addons/teambonus/template/platform/updateTeamAgentLevel.html";i:1572400553;}*/ ?>

		<!-- page -->
		<form class="form-horizontal form-validate pt-15 widthFixedForm">
			<input type="hidden" id=level_id value="<?php echo $id; ?>">
			<div class="form-group">
				<label class="col-md-2 control-label"><span class="text-bright">*</span>等级名称</label>
				<div class="col-md-5">
					<input type="text" class="form-control" name="level_name" required value="<?php if($list['level_name']): ?><?php echo $list['level_name']; endif; ?>" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label"><span class="text-bright">*</span>分红比例</label>
				<div class="col-md-5">
					<div class="input-group">
						<input type="number" class="form-control" min="0" max="100" name="ratio" required value="<?php if($list['ratio']): ?><?php echo $list['ratio']; endif; ?>" >
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label"><span class="text-bright">*</span>拿下级业绩比例</label>
				<div class="col-md-5">
					<div class="input-group">
						<input type="number" class="form-control" min="0" max="100" name="ratio1" required value="<?php if($list['ratio1']): ?><?php echo $list['ratio1']; endif; ?>" >
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>

			<?php if($list['is_default']!=1): ?>
			<div class="form-group">
				<label class="col-md-2 control-label">自动升级</label>
				<div class="col-md-5">
					<div class="switch-inline">
						<input type="checkbox" id="upgrade-switch" value="1" name="upgradetype" <?php if($list['upgradetype']==1): ?>checked<?php endif; ?>>
						<label for="upgrade-switch"></label>
					</div>
					<div class="help-block mb-0">开启后满足一定条件自动升级，关闭后则该等级不会自动升级。</div>
				</div>
			</div>
			<div id="isupgrade" class="<?php if($list['upgradetype']!=1): ?>hide<?php endif; ?>">
				<div class="form-group">
					<label class="col-md-2 control-label">升级条件</label>
					<div class="col-md-5">
						<div>
						<label class="radio-inline">
							<input type="radio"   value="1" name="upgradecondition" <?php if($list['upgrade_condition']==1): ?>checked<?php endif; ?>> 满足所有勾选条件
						</label>
						<label class="radio-inline">
							<input type="radio"  value="2" name="upgradecondition" <?php if($list['upgrade_condition']==2): ?>checked<?php endif; ?>> 满足勾选条件之一即可
						</label>
						</div>
					</div>
				</div>
				<div class="form-group" id="upgrade-condition">
					<label class="col-md-2 control-label"></label>
					<div class="col-md-8">
						<div class="form-additional" style="width: auto">
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="1"> 内购订单金额满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="pay_money" value="<?php if($list['pay_money']>0): ?><?php echo $list['pay_money']; endif; ?>">
										<div class="input-group-addon">元</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="3"> 一级分销商满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="one_number" value="<?php if($list['one_number']): ?><?php echo $list['one_number']; endif; ?>">
										<div class="input-group-addon">人</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="4"> 二级分销商满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="two_number" value="<?php if($list['two_number']): ?><?php echo $list['two_number']; endif; ?>" >
										<div class="input-group-addon" >人</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="5"> 三级分销商满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="three_number" value="<?php if($list['three_number']): ?><?php echo $list['three_number']; endif; ?>">
										<div class="input-group-addon">人</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="8"> 下线客户数达</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="offline_number" value="<?php if($list['number']): ?><?php echo $list['number']; endif; ?>">
										<div class="input-group-addon">人(非分销商)</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="2"> 团队人数</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="group_number" value="<?php if($list['group_number']): ?><?php echo $list['group_number']; endif; ?>">
										<div class="input-group-addon">人(分销商)</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="9"> 指定推荐等级</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<select class="form-control upgrade_level" style="min-width: 130px" name="upgrade_level">
											<?php foreach($level_info as $v): ?>
											<option value="<?php echo $v['id']; ?>" <?php if($list['upgrade_level']==$v['id']): ?>selected<?php endif; ?>><?php echo $v['level_name']; ?></option>
											<?php endforeach; ?>
										</select>
										<div class="input-group-addon">达</div>
										<input type="number" class="form-control" min="0" name="level_number" value="<?php if($list['level_number']): ?><?php echo $list['level_number']; endif; ?>">
										<div class="input-group-addon">人</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="6"> 一级订单金额满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="order_money" value="<?php if($list['order_money']>0): ?><?php echo $list['order_money']; endif; ?>">
										<div class="input-group-addon">元</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="11"> 团队订单金额满</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="up_team_money" value="<?php if($list['up_team_money']>0): ?><?php echo $list['up_team_money']; endif; ?>">
										<div class="input-group-addon">元</div>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="15"> 团队（三级内）</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<div class="input-group-addon">团队</div>
										<select class="form-control team_number_level" style="min-width: 130px" name="team_number_level">
											<?php foreach($level_info as $v): ?>
											<option value="<?php echo $v['id']; ?>" <?php if($list['team_number_level']==$v['id']): ?>selected<?php endif; ?>><?php echo $v['level_name']; ?></option>
											<?php endforeach; ?>
										</select>
										<div class="input-group-addon">达</div>
										<input type="number" class="form-control" min="0" name="team_numbers" value="<?php if($list['team_numbers']): ?><?php echo $list['team_numbers']; endif; ?>">
										<div class="input-group-addon">人</div>
										
									</div>
									<div class="input-group">
										<div class="input-group-addon">直推</div>
										<select class="form-control re_number_level" style="min-width: 130px" name="re_number_level">
											<?php foreach($level_info as $v): ?>
											<option value="<?php echo $v['id']; ?>" <?php if($list['re_number_level']==$v['id']): ?>selected<?php endif; ?>><?php echo $v['level_name']; ?></option>
											<?php endforeach; ?>
										</select>
										<div class="input-group-addon">达</div>
										<input type="number" class="form-control" min="0" name="re_number" value="<?php if($list['re_number']): ?><?php echo $list['re_number']; endif; ?>">
										<div class="input-group-addon">人</div>
										
									</div>
								</div>
							</div>


                          <div class="form-group">

								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="14"> 团队（三级内）</label>

								<div class="col-md-7 control-group">

									<div class="input-group">

										<input type="number" class="form-control" min="0" name="team_number_pay" value="<?php if($list['team_number_pay']): ?><?php echo $list['team_number_pay']; endif; ?>">

										<div class="input-group-addon">人消费且满</div>

										<input type="number" class="form-control" min="0" name="team_pay" value="<?php if($list['team_pay']): ?><?php echo $list['team_pay']; endif; ?>">

										<div class="input-group-addon">元</div>

									</div>

								</div>

							</div>


							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="upgradeconditions" value="7"> 购买指定商品</label>
								<div class="col-md-7 control-group">
									<div class="picture-list">
										<a href="javascript:;" class="<?php if($list['pic']): ?>close-box1 has-pic<?php else: ?>plus-box search_goods<?php endif; ?>">
											<?php if($list['pic']): ?>
											<i class='icon icon-danger' title='删除'></i><img src="<?php echo __IMG($list['pic']); ?>" style='width:80px;height:80px;margin: 0'>
											<?php else: ?>
											<i class="icon icon-plus"></i>
											<?php endif; ?>
										</a>
										<input type="text" class="visibility" data-visi-type="singlePicture" name="picture-Logo">
									</div>
									<input type="hidden" name='pic_id' id="pic_id" value="">
									<input type="hidden" name='selectgoods_id' id="selectgoods_id" value="<?php echo $list['goods_id']; ?>">
									<div class="input-group selectid">
										<?php if(($list['goods_id'])): ?>指定商品：<?php echo $list['goods_name']; endif; ?>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">自动降级</label>
				<div class="col-md-5">
					<div class="switch-inline">
						<input type="checkbox" id="downgrade-switch" value="1" name="downgradetype" <?php if($list['downgradetype']==1): ?>checked<?php endif; ?>>
						<label for="downgrade-switch"></label>
					</div>
					<div class="help-block mb-0">开启后不满足指定条件自动降级，关闭后则该等级不会自动降级。</div>
				</div>
			</div>
			<div id="isdowngrade" class="<?php if($list['downgradetype']!=1): ?>hide<?php endif; ?>">
				<div class="form-group">
					<label class="col-md-2 control-label">降级条件</label>
					<div class="col-md-5">
						<div>
						<label class="radio-inline">
							<input type="radio"  value="1" name="downgradecondition" <?php if($list['downgrade_condition']==1): ?>checked<?php endif; ?>> 满足所有勾选条件
						</label>
						<label class="radio-inline">
							<input type="radio" value="2" name="downgradecondition" <?php if($list['downgrade_condition']==2): ?>checked<?php endif; ?>> 满足勾选条件之一即可
						</label>
						</div>
					</div>
				</div>
				<div class="form-group" id="downgrade-condition">
					<label class="col-md-2 control-label"></label>
					<div class="col-md-8">
						<div class="form-additional" style="width: auto">
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="downgradeconditions" value="1"> 团队订单量</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="team_number_day" value="<?php if($list['team_number_day']): ?><?php echo $list['team_number_day']; endif; ?>">
										<div class="input-group-addon">天内，少于</div>
										<input type="number" class="form-control" min="0" name="team_number" value="<?php if($list['team_number']): ?><?php echo $list['team_number']; endif; ?>">
										<div class="input-group-addon">单</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="downgradeconditions" value="2"> 团队订单金额</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="team_money_day" value="<?php if($list['team_money_day']): ?><?php echo $list['team_money_day']; endif; ?>">
										<div class="input-group-addon">天内，少于</div>
										<input type="number" class="form-control" min="0" name="team_money" value="<?php if($list['team_money']>0): ?><?php echo $list['team_money']; endif; ?>">
										<div class="input-group-addon">元</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-4 control-label"><input type="checkbox" name="downgradeconditions" value="3"> 内购订单金额</label>
								<div class="col-md-7 control-group">
									<div class="input-group">
										<input type="number" class="form-control" min="0" name="self_money_day" value="<?php if($list['self_money_day']): ?><?php echo $list['self_money_day']; endif; ?>">
										<div class="input-group-addon">天内，少于</div>
										<input type="number" class="form-control" min="0" name="self_money" value="<?php if($list['self_money']>0): ?><?php echo $list['self_money']; endif; ?>">
										<div class="input-group-addon">元</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<input type="hidden" id="weight" value="<?php echo $list['weight']; ?>">
				<label class="col-md-2 control-label"><span class="text-bright">*</span>权重</label>
				<div class="col-md-5">
					<input type="number" class="form-control" name="weight" required value="<?php if($list['weight']): ?><?php echo $list['weight']; endif; ?>">
					<div class="help-block mb-0">等级权重，数字越大级别越高。按设置的权重大小从低到高进行升级。</div>
				</div>
			</div>
			<?php endif; ?>
			<div class="form-group"></div>
			<div class="form-group">
				<label class="col-md-2 control-label"></label>
				<div class="col-md-8">
					<button class="btn btn-primary add" type="submit">修改</button>
					<a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
				</div>
			</div>
		</form>

		<input type="hidden" value="<?php echo $level_weight; ?>" id="level_weight">


		<!-- page end -->



<script>
    require(['util'],function(util){
        loading();
        function loading() {
            var upgradeconditions = "<?php echo $list['upgradeconditions']; ?>";
            upgradeconditions = upgradeconditions.split(',');
            for (var i = 0; i < upgradeconditions.length; i++) {
                $('[name="upgradeconditions"][value="' + upgradeconditions[i] + '"]').prop("checked", true);
                if(upgradeconditions[i]!="7"){
                    $('[name="upgradeconditions"][value="' + upgradeconditions[i] + '"]').parent(".control-label").siblings(".control-group").find("input").attr("required",true);
                }
            }
            var downgradeconditions = "<?php echo $list['downgradeconditions']; ?>";
            downgradeconditions = downgradeconditions.split(',');
            for (var i = 0; i < downgradeconditions.length; i++) {
                $('[name="downgradeconditions"][value="' + downgradeconditions[i] + '"]').prop("checked", true);
                $('[name="downgradeconditions"][value="' + downgradeconditions[i] + '"]').parent(".control-label").siblings(".control-group").find("input").attr("required",true);
            }
        }
        $("#upgrade-switch").change(function () {
            var upgradetype = $("input[name='upgradetype']:checked").val();
            if(upgradetype==1){
                $("input[name='upgradecondition']").attr("required",true);
				$("#isupgrade").removeClass("hide");
            }else{
                $("input[name='upgradecondition']").removeAttr("required",true);
				$("#isupgrade").addClass("hide");
            }
        })
        $("#downgrade-switch").change(function () {
            var downgradetype = $("input[name='downgradetype']:checked").val();
            if(downgradetype==1){
                $("input[name='downgradecondition']").attr("required",true);
				$("#isdowngrade").removeClass("hide");
            }else{
                $("input[name='downgradecondition']").removeAttr("required",true);
				$("#isdowngrade").addClass("hide");
            }
        })
        $("input[name='upgradeconditions']").click(function () {
			var vals = $(this).val();
			if(vals != 7){
				if($(this).is(':checked')){
					$(this).parent(".control-label").siblings(".control-group").find("input").attr("required",true);
				} else{
					$(this).parents(".form-group").removeClass('has-error');
					$(this).parents(".form-group").find('.help-block-error').html('');
					$(this).parent(".control-label").siblings(".control-group").find("input").removeAttr("required",true);
				}
			}else{
				if($(this).is(':checked')){
					if($('.close-box1').hasClass('has-pic')){

					}else{
						$(this).parent(".control-label").siblings(".control-group").find("input").attr("required",true);
					}
				}else{
					$(this).parents(".form-group").removeClass('has-error');
					$(this).parents(".form-group").find('.help-block-error').html('');
					$(this).parent(".control-label").siblings(".control-group").find("input").removeAttr("required",true);
				}
			}

        })
        $("input[name='downgradeconditions']").click(function () {
            if($(this).is(':checked')){
                $(this).parent(".control-label").siblings(".control-group").find("input").attr("required",true);
            } else{
                $(this).parents(".form-group").removeClass('has-error');
                $(this).parents(".form-group").find('.help-block-error').html('');
                $(this).parent(".control-label").siblings(".control-group").find("input").removeAttr("required",true);
            }
        })
        $("input[name='weight']").on('blur',function () {
            var default_weight = $("#weight").val();
            var weight = $("input[name='weight']").val();
            var arr = $("#level_weight").val();
            arr = arr.split(',');
            for(var i = 0; i < arr.length; i++){
                if(weight === arr[i] && default_weight != arr[i]){
                    util.message('该等级权重值已存在','danger');
                    $("input[name='weight']").val('');
                    return false;
                }
            }
        })
        function isInArray(arr,value){
            for(var i = 0; i < arr.length; i++){
                if(value === arr[i]){
                    return true;
                }
            }
            return false;
        }
        util.validate($('.form-validate'),function(form){
            var level_name = $("input[name='level_name']").val();
            var ratio = $("input[name='ratio']").val();
            var upgradetype = $("input[name='upgradetype']:checked").val();
            var upgrade_level = $(".upgrade_level").val();
            var level_number = $("input[name='level_number']").val();
            var offline_number = $("input[name='offline_number']").val();
            var group_number = $("input[name='group_number']").val();
            var one_number = $("input[name='one_number']").val();
            var two_number = $("input[name='two_number']").val();
            var three_number = $("input[name='three_number']").val();
            var order_money = $("input[name='order_money']").val();
            var pay_money = $("input[name='pay_money']").val();
            var downgradetype = $("input[name='downgradetype']:checked").val();
            var team_number = $("input[name='team_number']").val();
            var team_money = $("input[name='team_money']").val();
            var up_team_money = $("input[name='up_team_money']").val();
            var self_money = $("input[name='self_money']").val();
            var team_number_day = $("input[name='team_number_day']").val();
            var team_money_day = $("input[name='team_money_day']").val();
            var self_money_day = $("input[name='self_money_day']").val();
            var upgrade_condition = $("input[name='upgradecondition']:checked").val();
            var downgrade_condition = $("input[name='downgradecondition']:checked").val();

            var team_number_pay = $("input[name='team_number_pay']").val();

            var team_pay = $("input[name='team_pay']").val();

            var team_number_level = $(".team_number_level").val();

            var team_numbers = $("input[name='team_numbers']").val();

            var re_number_level = $(".re_number_level").val();

            var re_number = $("input[name='re_number']").val();

            var ratio1 = $("input[name='ratio1']").val();

            var weight = $("input[name='weight']").val();
            var upgradeconditions = $("input:checkbox[name='upgradeconditions']:checked").map(function(index,elem) {
                return $(elem).val();
            }).get().join(',');
            var arr=upgradeconditions.split(',');
            if(isInArray(arr,"7")){
                var goods_id = $("input[name='selectgoods_id']").val();
            }else{
                var goods_id ='';
            }
            var downgradeconditions = $("input:checkbox[name='downgradeconditions']:checked").map(function(index,elem) {
                return $(elem).val();
            }).get().join(',');
            if(upgradetype==1 && upgradeconditions==''){
                util.message('请填写升级条件','danger');
                return false;
            }
            if(downgradetype==1 && downgradeconditions==''){
                util.message('请填写降级条件','danger');
                return false;
            }
            $('.add').attr({disabled: "disabled"}).html('提交中...');
            $.ajax({
                type: "post",
                url: "<?php echo $updateTeamAgentLevelUrl; ?>",
                data: {
                    'id':$("#level_id").val(),
                    'level_name':level_name,
                    'ratio':ratio,
                    'upgradetype': upgradetype,
                    'upgrade_level':upgrade_level,
                    'level_number':level_number,
                    'offline_number':offline_number,
                    'group_number':group_number,
                    'one_number':one_number,
                    'two_number':two_number,
                    'three_number':three_number,
                    'pay_money':pay_money,
                    'order_money':order_money ,
                    'downgradetype':downgradetype,
                    'team_number':team_number,
                    'team_money':team_money,
                    'up_team_money':up_team_money,
                    'self_money':self_money,
                    'team_number_day':team_number_day,
                    'team_money_day':team_money_day,
                    'self_money_day':self_money_day,
                    'weight': weight,
                    'downgradeconditions':downgradeconditions,
                    'upgradeconditions': upgradeconditions,
                    'downgrade_condition':downgrade_condition,
                    'upgrade_condition': upgrade_condition,

                    'team_number_pay': team_number_pay,
                    'team_pay': team_pay,
                    'team_number_level': team_number_level,
                    'team_numbers': team_numbers,
                    're_number_level': re_number_level,
                    're_number': re_number,
                    'ratio1': ratio1,
                    
                    'goods_id':goods_id
                },
                async: true,
                success: function (data) {
                    if (data['code'] > 0) {
                        util.message(data["message"], 'success', "<?php echo __URL('ADDONS_MAINteamAgentLevelList'); ?>");
                    }else{
                        if(data['code'] ==-2) {
                            util.message('该等级已存在', 'danger');
                        }else if(data['code'] ==-3) {
                            util.message('等级总比例超过100%', 'danger');
                        }else {
                            util.message(data["message"], 'danger');
                        }
                        $('.add').removeAttr('disabled').html('修改');
					}
                }
            });

        })
        $('body').on('click','.search_goods', function () {
            var url = "<?php echo __URL('PLATFORM_MAIN/goods/selectGoodsList'); ?>";
            util.confirm('选择商品','url:'+url, function () {
                var data = this.$content.find('.goods_val').val();
                var pic = $('#pic_id').val();
                $(".selectid").html('指定商品：'+data);
                html='';
                html += "<i class='icon icon-danger' title='删除'></i><img src="+__IMG(pic)+" style='width:80px;height:80px;margin:0;'>";
                $(".search_goods").find('.visibility').removeAttr("required");
                $(".search_goods").addClass('close-box1').addClass('has-pic').removeClass('plus-box').removeClass('search_goods');
                $(".close-box1").html(html);
                $(".close-box1").siblings('.visibility').removeAttr("required");
            },'large')

        })
    })
</script>
